#Author:jtt
#Content:XunLianYing
from selenium import webdriver


class Test:
    def setup(self):
        self.driver = webdriver.Chrome()
        self.driver.get('http://localhost')
        self.driver.implicitly_wait(5)

    def test_login_pass(self):
        self.driver.find_element_by_link_text('登录').click()
        self.driver.find_element_by_id('username').send_keys('13800138006')
        self.driver.find_element_by_id('password').send_keys('123456')
        self.driver.find_element_by_id('verify_code').send_keys('8888')

        self.driver.find_element_by_name('sbtbutton').click()

        msg = self.driver.find_element_by_class_name("mu-m-phone").text
        assert msg == 'summer',"断言提示信息，预期结果【summer】，实际结果【%s】"%msg
        print('登录成功')

    def test_account_not_exists(self):
        self.driver.find_element_by_link_text('登录').click()
        self.driver.find_element_by_id('username').send_keys('13800138000')
        self.driver.find_element_by_id('password').send_keys('123456')
        self.driver.find_element_by_id('verify_code').send_keys('8888')

        self.driver.find_element_by_name('sbtbutton').click()

        msg = self.driver.find_element_by_class_name("layui-layer-padding").text
        assert msg == '账号不存在!', "断言提示信息，预期结果【账号不存在!】，实际结果【%s】" % msg
        print('提示信息验证通过!')

    def test_password_is_error(self):
        self.driver.find_element_by_link_text('登录').click()
        self.driver.find_element_by_id('username').send_keys('13800138006')
        self.driver.find_element_by_id('password').send_keys('1234567')
        self.driver.find_element_by_id('verify_code').send_keys('8888')
        self.driver.find_element_by_name('sbtbutton').click()

        msg = self.driver.find_element_by_class_name("layui-layer-padding").text
        assert msg == '密码错误!',"断言提示信息，预期结果【密码错误!】，实际结果【%s】"%msg
        print('提示信息验证通过!')

    def test_add_to_cart(self):
        self.driver.find_element_by_id('q').send_keys('手机')
        self.driver.find_element_by_class_name('ecsc-search-button').click()
        self.driver.find_element_by_class_name('p-btn').click()
        self.driver.find_element_by_id('join_cart').click()

        #两种方式都可以
        self.driver.switch_to.frame("layui-layer-iframe1")
       # self.driver.switch_to.frame(self.driver.find_elements_by_tag_name("ifame"))

        msg = self.driver.find_element_by_css_selector(".conect-title > span:nth-child(1)").text
        print(msg)
        assert msg == '添加成功', "断言提示信息，预期结果【添加成功】，实际结果【%s】" % msg
        print('提示信息验证通过!')